<?php
class BudgetAction extends MY_Controller {
	function BudgetAction() {
		parent::MY_Controller ();
	}
	/**
	 * 预算初始化页面
	 */
	function index() {
		$this->load->model('user/budgetmodel', "budgetmodel", true);
		$mydata = $this->budgetmodel->get_budget_by_user_id($this->session->userdata ( 'user_id' ));
		if ($mydata) {
			for ($i = 1; $i <= 15; $i++ ) {
				$key = "f_".$i;
				if ($mydata[$key] == 0) {
					$mydata[$key] = "";
				}
			}
			$data['budget'] = $mydata;
			$this->load->view ( "user/budget_index", $data );
			return;	
		}
		$this->load->view ( "user/budget_index");
		
	}
	/**
	 * ajax保存处理
	 */
	function ajax_save() {
		$this->load->model('user/budgetmodel', "budgetmodel", true);
		$form_data = $this->_form_data(array('date'));
		$form_data['user_id'] = $this->session->userdata ( 'user_id' );
		$this->budgetmodel->save_budget($form_data);
		echo "保存成功";
	}
}